package com.guigu.www.erp.common.interceptor;

import com.guigu.www.erp.dehao.pojo.User;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User login = (User) request.getSession().getAttribute("loginUser");
        Object loginUserId = request.getSession().getAttribute("loginUserId");

        if (login!=null || loginUserId!=null){
            return true;
        }else {
            //request.getRequestDispatcher("/examples/login.html").forward(request,response);
            response.sendRedirect("/examples/login.html");
            return false;
        }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
